// 格式化
package formats

import (
	"goHelpers/helper/constraints"

	"gitee.com/copylian/lian-go.git/helper/slices"
)

// RecursiveList 递归处理数据
func RecursiveList[T constraints.Recursive](data T, pid uint32, selectIds []uint32) (res T) {
	for _, v := range data {
		// 选中
		if slices.Contains(selectIds, v.Id) {
			v.Checked = 1
		}
		if v.Pid == pid {
			v.Child = RecursiveList(data, v.Id, selectIds)
			if v.Child == nil {
				v.Child = make(T, 0)
			}
			res = append(res, v)
		}
	}
	return
}
